import socket

class Curry:
    """Curry arguments to the function for later invocation"""
    def __init__(self, f, *args):
        self.f = f
        self.args = args

    def __call__(self, *args):
        a = list(self.args)
        a.extend(args)
        return self.f(*a)

def curry_method(f):
    """Function decorator @curry_method"""
    def wrapper(self, *args):
        return Curry(f, self, *args)
    return wrapper

def sock_readln(sock):
    """Read line from socket"""
    b = ''
    while True:
        c = sock.recv(1)
        if c == '':
            return ''
        elif c == '\n':
            break
        b = b + c
    return b

def assert_sock_nread(sock, values):
    """Check that the values were read from the socket, in any
    order. This handles cases of non-determinism"""
    while len(values) > 0:
        s = sock_readln(sock)
        if s in values:
            values.remove(s)
        else:
            assert False, '"%s" is not an expected value' % s
